package impl

import (
	"gitee.com/zatto/maudit/apps/audit"
	"gitee.com/zatto/maudit/conf"
	"github.com/infraboard/mcube/app"
	"go.mongodb.org/mongo-driver/mongo"
)

var (
	svc = &impl{}
)

type impl struct {
	col *mongo.Collection
}

func (i *impl) Config() error {
	db, err := conf.C().Mongo.GetDB()
	if err != nil {
		return err
	}

	i.col = db.Collection(audit.AppName)
	return nil
}

func (i *impl) Name() string {
	return audit.AppName
}

func (i *impl) getCol() *mongo.Collection {
	if i.col == nil {
		panic("Init internal App first")
	}
	return i.col
}

func init() {
	app.RegistryInternalApp(svc)
}
